package handlers

import (
	"github.com/gofiber/fiber/v2"
	"notabug.org/alimiracle/my-website-api/models"
	"notabug.org/alimiracle/my-website-api/responses"
)

func (self Handler) GetAllJobs(c *fiber.Ctx) error {
	var jobs []models.Job
	self.Database.FindAll(&jobs)
	return c.Status(fiber.StatusOK).JSON(&jobs)
}

func (self Handler) AddJob(c *fiber.Ctx) error {
	body := models.Job{}
	if err := c.BodyParser(&body); err != nil {
		return responses.BadRequestResponse(c, err)
	}
	// insert new db entry
	err := self.Database.Create(&body)
	return responses.Created_Response(c, &body, err)
}
func (self Handler) UpdateJob(c *fiber.Ctx) error {
	id := c.Params("id")
	body := models.Job{}
	if err := c.BodyParser(&body); err != nil {
		return responses.BadRequestResponse(c, err)
	}
	err := self.Database.Update(&body, id)
	return responses.Response(c, err)
}
func (self Handler) DeleteJob(c *fiber.Ctx) error {
	id := c.Params("id")

	var job models.Job
	err := self.Database.Delete(&job, id)
	return responses.Response(c, err)
}
